package com.sskj.mine.asset;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.mine.asset.data.ExchangeConfigBean;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.presenter.BasePresenter;
import com.sskj.mine.asset.ExchangeActivity;


/**
 * @author Hey
 * Create at  2019/05/04
 */
class ExchangePresenter extends BasePresenter<ExchangeActivity> {


    /**
     * 兑换页面
     *
     * @param type 1代币兑usdt 2 usdt兑换代币
     * @return
     */
    public void getExchangeConfig(String type) {
        httpService.getExchangeConfig(type).execute(new JsonCallBack<HttpData<ExchangeConfigBean>>() {
            @Override
            public void onSuccess(Response<HttpData<ExchangeConfigBean>> response) {
                HttpData<ExchangeConfigBean> httpData = response.body();
                if (httpData.getStatus() == HttpConfig.OK) {

                    mView.updateConfig(httpData.getData());
                }
            }
        });
    }

    /**
     * 确认兑换
     *
     * @param type 1代币兑usdt 2 usdt兑换代币
     * @param num  兑换数量
     * @param tpwd 交易密码
     * @return
     */
    public void cash(String type, String num, String tpwd) {
        httpService.cash(type, num, tpwd).execute(new JsonCallBack<HttpData>(this) {
            @Override
            public void onSuccess(Response<HttpData> response) {
                HttpData httpData = response.body();
                ToastUtil.showShort(httpData.getMsg());
                if (httpData.getStatus() == HttpConfig.OK) {

                    mView.cashSuccess();
                }
            }
        });
    }
}
